package libs

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"io/ioutil"
	"net/http"
)

func DebugRequest(c *gin.Context) {
	// Print request headers
	fmt.Println("Headers:")
	for key, values := range c.Request.Header {
		for _, value := range values {
			fmt.Printf("%s: %s\n", key, value)
		}
	}

	// Print request body
	body, err := ioutil.ReadAll(c.Request.Body)
	if err != nil {
		c.String(http.StatusBadRequest, "Failed to read request body")
		return
	}
	fmt.Println("Body:")
	fmt.Println(string(body))

	// Print request form data
	if err := c.Request.ParseForm(); err == nil {
		fmt.Println("Form Data:")
		for key, values := range c.Request.PostForm {
			for _, value := range values {
				fmt.Printf("%s: %s\n", key, value)
			}
		}
	}
}
